import { BusiserviceProvider } from './../../providers/busiservice/busiservice';
import { LoadingController } from 'ionic-angular';
import { UiserviceProvider } from './../../providers/uiservice/uiservice';
import { LoadingUtil } from './../../common/loading';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the OrderdetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-orderdetail',
  templateUrl: 'orderdetail.html',
})
export class OrderdetailPage {
  order:any;
  loading: LoadingUtil;
  rate:any;
  pjxx:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busiservice: BusiserviceProvider, private loadingCtrl: LoadingController, private uiservice: UiserviceProvider) {
    this.order = this.navParams.get("order");
    this.rate = this.order.star;
    this.pjxx =this.order.comment;
    this.loading = new LoadingUtil(this.loadingCtrl);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad OrderdetailPage');
  }
  jiedan(){
    this.loading.showLoading();
    this.busiservice.jd(this.order.orderid).subscribe(
      data => {
        if (data._success) {
          this.loading.hideLoading();
          this.uiservice.showToast("接单成功！");
          this.navCtrl.pop();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }
  completeOrder(){
    this.loading.showLoading();
    this.busiservice.completeOrder(this.order.orderid).subscribe(
      data => {
        if (data._success) {
          this.loading.hideLoading();
          this.uiservice.showToast("订单完成成功！");
          this.navCtrl.pop();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }

}
